﻿using HB.Base;
using HB.MVVM;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace MyDemoDll
{
    public class VMMainWindow : ViewModelBase<VMMainWindow>
    {
        public override void VM_Init(object sender, RoutedEventArgs e)
        {
            IocResolve(out resetZoom);
            IocResolve(out savetopng);
        }

        public bool show1 { get => GetBool(); set => Set(value); }
        public bool show2 { get => GetBool(true); set => Set(value); }
        public bool show3 { get => GetBool(); set => Set(value); }
        public bool show4 { get => GetBool(); set => Set(value); }
        public GearedValues<double> chartdata { get; set; } = new GearedValues<double>();

        TriggerTimer timer = new TriggerTimer();
        Random r = new Random();
        Action resetZoom;
        Action<string> savetopng;
        public string Rand { get => GetString(); set => Set(value); }
        public ICommand cmdrun => GetCommand(() =>
        {
            chartdata.Clear();
            timer.Start(60, (t, i) =>
            {
                chartdata.Add(DateTime.Now.Second + r.Next(10));
                Rand = r.Next(1, 100).ToString();
            });

        });
        public ICommand cmdstop => GetCommand(() =>
        {

            timer.Stop();
        });
        public ICommand cmdresetzoom => GetCommand(() =>
        {
            //   resetZoom.Invoke();
            chartdata.Chart.ResetZoom();
        });
        public ICommand cmdresetzoom2 => GetCommand(() =>
        {
            //   resetZoom.Invoke();
            chartdata.Chart.ResetZoom(1, 100);
        });

        public ICommand cmdsavepng => GetCommand(() =>
        {
            savetopng.Invoke("o:\\hhhh.png");
        });
    }
}
